package com.coolgor.axnut.web.mdmis;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


import com.coolgor.axnut.entity.mdmis.PolicyCondition;
import com.coolgor.axnut.service.mdmis.PolicyStatisticsService;


@Controller
@RequestMapping(value="mdmis", method={RequestMethod.GET,RequestMethod.POST})
public class PolicyStatisticsController {
	@Autowired
	private  PolicyStatisticsService policyStatisticsService;
	
	@RequestMapping(value = "/countReceiptRateByProject", method={RequestMethod.POST})
	@ResponseBody
	private Map<String, Object> countReceiptRateByProject(@RequestBody PolicyCondition policyCondition, HttpServletRequest request) {
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<Map<String, Object>> result;
		result = policyStatisticsService.countReceiptRateByProject(policyCondition);
		if (null != result ) {
			try {
				modelMap.put("total",result.size());
				modelMap.put("rows",result);
				modelMap.put("success", true);
			} catch (Exception e) {
				modelMap.put("success", false);
				modelMap.put("errMsg", e.toString());
			}
		} else {
			modelMap.put("success", false);
			modelMap.put("errMsg", "Empty List");
		}
		return modelMap;
	}	
	
	@RequestMapping(value = "/countReceiptRateByArea", method={RequestMethod.POST})
	@ResponseBody
	private Map<String, Object> countReceiptRateByArea(@RequestBody PolicyCondition policyCondition, HttpServletRequest request) {
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<Map<String, Object>> result;
		result = policyStatisticsService.countReceiptRateByArea(policyCondition);
		if (null != result ) {
			try {
				modelMap.put("total",result.size());
				modelMap.put("rows",result);
				modelMap.put("success", true);
			} catch (Exception e) {
				modelMap.put("success", false);
				modelMap.put("errMsg", e.toString());
			}
		} else {
			modelMap.put("success", false);
			modelMap.put("errMsg", "Empty List");
		}
		return modelMap;
	}	
	
	@RequestMapping(value = "/countTimelinessByProject", method={RequestMethod.POST})
	@ResponseBody
	private Map<String, Object> countTimelinessByProject(@RequestBody PolicyCondition policyCondition, HttpServletRequest request) {
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<Map<String, Object>> result;
		result = policyStatisticsService.countTimelinessByProject(policyCondition);
		if (null != result ) {
			try {
				modelMap.put("total",result.size());
				modelMap.put("rows",result);
				modelMap.put("success", true);
			} catch (Exception e) {
				modelMap.put("success", false);
				modelMap.put("errMsg", e.toString());
			}
		} else {
			modelMap.put("success", false);
			modelMap.put("errMsg", "Empty List");
		}
		return modelMap;
	}	
	
	@RequestMapping(value = "/countTimelinessByArea", method={RequestMethod.POST})
	@ResponseBody
	private Map<String, Object> countTimelinessByArea(@RequestBody PolicyCondition policyCondition, HttpServletRequest request) {
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<Map<String, Object>> result;
		result = policyStatisticsService.countTimelinessByArea(policyCondition);
		if (null != result ) {
			try {
				modelMap.put("total",result.size());
				modelMap.put("rows",result);
				modelMap.put("success", true);
			} catch (Exception e) {
				modelMap.put("success", false);
				modelMap.put("errMsg", e.toString());
			}
		} else {
			modelMap.put("success", false);
			modelMap.put("errMsg", "Empty List");
		}
		return modelMap;
	}		
	
	@RequestMapping(value = "/countByIntroMonth", method={RequestMethod.POST})
	@ResponseBody
	private Map<String, Object> countByIntroMonth(@RequestBody PolicyCondition policyCondition, HttpServletRequest request) {
		Map<String, Object> modelMap = new HashMap<String, Object>();
		List<Map<String, Object>> result = policyStatisticsService.countByIntroMonth(policyCondition);
		if (null != result ) {
			try {
				modelMap.put("total",result.size());
				modelMap.put("rows",result);
				modelMap.put("success", true);
			} catch (Exception e) {
				modelMap.put("success", false);
				modelMap.put("errMsg", e.toString());
			}
		} else {
			modelMap.put("success", false);
			modelMap.put("errMsg", "Empty List");
		}
		return modelMap;
	}	
}
